package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 苏靓仔
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
@Api("套餐相关接口")
public class SetmealController {

	@Resource
	private SetmealService setmealService;
	/**
	 * 新增套餐
	 * @param setmealDTO
	 * @return
	 */
	@PostMapping
	@ApiOperation("新增套餐")
	public Result save(@RequestBody SetmealDTO setmealDTO){
		log.info("新增套餐:{}",setmealDTO);
		setmealService.saveWithDish(setmealDTO);
		return Result.success();
	}

	@GetMapping("/page")
	@ApiOperation("分页查询")
	public Result<PageResult> setmealQuery(SetmealPageQueryDTO setmealPageQueryDTO){
		log.info("SetmealController-分页查询-setmealPageQueryDTO:{}",setmealPageQueryDTO);
		PageResult pageResult = setmealService.setmealPageQuery(setmealPageQueryDTO);
		return Result.success(pageResult);
	}

	@DeleteMapping()
	@ApiOperation("批量删除套餐")
	public Result delete(@RequestParam List<Long> ids){
		log.info("ids={}",ids);
		setmealService.deleteById(ids);
		return Result.success();
	}

	@PostMapping("/status/{status}")
	@ApiOperation("套餐起售、停售")
	public Result startOrStop(@PathVariable Integer status,Long id){
		setmealService.startOrStop(status,id);
		return Result.success();
	}
}
